package com.alpha.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletVerifAuth
 */
public class Authentication extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Authentication() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		PrintWriter out = response.getWriter();
		String pass = request.getParameter("inputPassword");
		String login = request.getParameter("inputLogin");
		
		if(pass != null && login != null && pass.equals("plop")){
			request.getRequestDispatcher("menu.html").forward(request, response);
		}
		else if(pass != null && login!=null && !pass.equals("plop")){
			out.println("<html><head><title>Fail !!!!!</title></head>");
			out.println("<body>");
			out.println("fail");
			out.println("</body>");
			out.println("</html>");
		}
	}

}
